{template 'common/header'}
{template 'nav'}
<div class="panel panel-default">
    <div class="panel-heading">筛选</div>
    <div class="panel-body">
        <form action="./index.php" method="get" class="form-horizontal" role="form" id="form1">
            <input type="hidden" name="c" value="site" />
            <input type="hidden" name="a" value="entry" />
            <input type="hidden" name="m" value="meepo_xianchang" />
            <input type="hidden" name="do" value="lottory_receive" />

            <input type="hidden" name="id" value="{$id}" />

            <div class="form-group">
                <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">中奖人</label>
                <div class="col-xs-12 col-sm-8 col-lg-8">
                    <input class="form-control" name="nickname" id="" type="text" value="{$_GPC['nickname']}" placeholder="清输入姓名">
                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label"></label>
                <div class="col-sm-8 col-lg-9 col-xs-12">
                    <input class="btn btn-primary" id="" type="submit" value="搜索">
                </div>
            </div>
        </form>
    </div>
</div>
<div class="main panel panel-default" id="table-list">
    <div class="sub-title panel-heading">中奖名单</div>
    <div class="panel-body">
        <form action="" method="post" onsubmit="">
            <div class="sub-content table-responsive">
                <table class="table table-hover">
                    <thead class="navbar-inner">
                    <tr>
                        <th class="row-hover" style="width:5em;">选择</th>
                        <th class="row-hover" style="width:10em;">中奖用户</th>
                        <th class="row-hover" style="width:5em;">奖项</th>
                        <th class="row-hover" style="width:10em;">奖品名称</th>
                        <th class="row-hover" style="width:15em;">中奖时间</th>
                        <th class="row-hover" style="width:8em;">是否领奖</th>
                        <th class="row-hover" style="width:8em;">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {loop $list $row}
                    <tr>
                        <td class="row-first"><input type="checkbox" name="select[]" value="{$row['id']}" /></td>
                        <td class="row-hover"><img src="{$row['avatar']}" height=40px width=40px /><br/>{$row['nick_name']}</td>
                        <td class="row-hover">{$row['tag_name']}</td>
                        <td class="row-hover">{$row['luck_name']}</td>
                        <td style="font-size:12px; color:#666;">
                            {php echo date('Y-m-d H:i:s', $row['createtime']);}
                        </td>
                        <td style="font-size:12px; color:#666;">
                            {php echo $row['is_receive'] == "1" ? "<font color='green'>已领</font>" : "<font color='red'>否</font>"}
                        </td>
                        <td style="font-size:12px; color:#666;">{php echo $row['is_receive'] == "1" ? "-" : ('<button type="button" onclick="take('.$row['user_id'].',[],-1)">领奖</button>')}</td>
                    </tr>
                    {/loop}
                    </tbody>
                </table>

            </div>
        </form>
    </div>
    {$pager}
</div>
{template 'common/footer'}
<script>
    function getLottory(){
        $.ajax({
            url:"http://wy.linewell.com/web/index.php?c=site&a=entry&do=lottory_real&m=meepo_xianchang&t="+new Date().getTime(),
            dataType:"json",
            async: false,
            cache: false,
            success: function(data){
                if(data.errno==0){
                    var ids = data.message;
                    var idArr = ids.split(",");
                    var index = 0;
                    open(idArr,index);
                }else{
                    console.log(data.message);
                    setTimeout('getLottory()',500);
                }
            }
        })
    }
    function open(idArr,index){
        layer.open({
            type: 2,
            title: false,
            area: ['330px', '560px'],
            shade: 0.8,
            closeBtn: 0,
            shadeClose: false,
            content: 'http://wy.linewell.com/app/index.php?i=1&c=entry&t=1517193107&do=app_winning&m=meepo_xianchang&userId='+idArr[index]+'&nobutton=none',
            btn: ['领奖', '取消'],
            yes:function(layerIndex, layero){
                take(idArr[index],idArr,index);
                layer.close(layerIndex);
            },
            btn2:function(layerIndex, layero){
                $.ajax({
                    url:"http://wy.linewell.com/web/index.php?c=site&a=entry&do=lottory_del&m=meepo_xianchang&t="+new Date().getTime(),
                    dataType:"json",
                    async: false,
                    cache: false,
                    success: function(data){
                        console.log(data.message);
                        setTimeout('getLottory()',500);
                        layer.close(layerIndex);
                    }
                })
            }
        });
    }

    function take(userId,idArr,index){
        $.ajax({
            url:"http://wy.linewell.com/web/index.php?c=site&a=entry&do=lottory_take&m=meepo_xianchang&t="+new Date().getTime(),
            dataType:"json",
            async: false,
            cache: false,
            data:{
                userId:userId
            },
            success: function(data){
                console.log(data.message);
                /*if(idArr.length-1 != index){
                    open(idArr,index+1);
                }else{
                    location.reload();
                    //setTimeout('getLottory()',500);
                }*/
                location.reload();
            }
        })
    }
    getLottory();
</script>
